<template>
	<body-wrap>
		<view class="comment">
			<view class="cmList">
				<view class="imgbox">
					<cm-image v-if="detail.userId" :src="detail.userId.avatar"/>
				</view>
				<view class="mainbox" style="border: 0;" v-if="detail.userId">
					<text class="name">{{detail.userId.name || detail.userId.nickname}}</text>
					<text class="time">{{dateFormat('Y-m-d H:i',detail.createTime)}}</text>
					<view class="cmDtBox">{{detail.questionContent}}</view>
				</view>
			</view>
		</view>
		<view class="pltitle">全部回复 {{total}}条</view>
		<!-- <view class="comment">
			<view class="cmList" v-for="dt in lists" :key="dt._id">
				<min-teacher-info :infor="dt.userId"/>
				<view class="replyDetailBox"></view>
			</view>
		</view> -->
		<view class="zjListBox">
			<navigator class="zjListItem" v-for="dt in lists" :key="dt._id" :url="`/pages/qa/replyDetail?id=${dt._id}`">
				<view class="tcInfo">
					<min-teacher-info :infor="dt.userId"/>
				</view>
				<view class="zjjgprice">
					<template v-if="dt.price && dt.price>0">
						¥<text class="num">{{dt.price}}</text>
					</template>
					<template v-else>免费</template>
				</view>
				<view class="lk">
					<i class="iconfont icon-xiangyoujiantou"></i>
				</view>
			</navigator>
		</view>

	</body-wrap>
</template>

<script>
	import {defineComponent,reactive,toRefs,onMounted,getCurrentInstance,computed} from 'vue'
	import {onLoad,onShow} from '@dcloudio/uni-app'
	import { useStore } from 'vuex'
	import bodyWrap from "@/components/bodyWrap/index.vue"
	import cmImage from "@/components/cmImage/index.vue"
	import minTeacherInfo from "@/components/minTeacherInfo/index.vue"
	import {dateFormat} from "@/utils/common.js"
	import {toast} from "@/utils/common.js"
	import {getQuestionDetail,getCommentList,addComment} from "@/api/consult.js"
	export default defineComponent({
		components:{
			bodyWrap,
			cmImage,
			minTeacherInfo
		},
		props:{
		
		},
		setup(props,context) {
			const store = useStore()
			const {proxy} = getCurrentInstance()
			
			const state = reactive({
				userInfo:computed(()=>store.state.base.userInfo),
				content:'',
				qid:'',
				detail:{},
				lists:'',
				pageIndex:1,
				pageSize:20,
				total:0,
			})
			
			onLoad(options=>{
				if(options && options.id){
					state.qid = options.id
				}
				get_question_detail()
				get_teacher_reply()
			})
			
			const get_question_detail = async ()=>{
				const res = await getQuestionDetail(state.qid)
				if(res.code == 200){
					state.detail = res.data
				}
			}
			
			// 获取教师回复
			const get_teacher_reply = async ()=>{
				getCommentList({
					pageIndex:state.pageIndex,
					pageSize:state.pageSize,
					questionId:state.qid,
					privacy:1, // 公开
					type:5 // 教师回复
				}).then(res =>{
					if(res.code == 200){
						state.lists = res.data.data
						state.total = res.data.total
					}
				})
			}
		
			
			onMounted(()=>{
				
			})

			return {
				...toRefs(state),
				dateFormat,
			}
		}
	})
</script>

<style lang="scss" scoped>
	.comment{
		padding: 0 20rpx;
		box-sizing: border-box;
		width: 100%;
		background: #fff;
		.cmList{
			display: flex;
			box-sizing: border-box;
			padding: 20rpx 0 0 0;
			.imgbox{
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
				overflow: hidden;
				flex-shrink: 0;
			}
			.mainbox{
				flex: 1;
				box-sizing: border-box;
				flex-shrink: 0;
				padding: 0 0 20rpx 10rpx;
				line-height: normal;
				width: 100%;
				border-bottom: 1px solid #f2f2f2;
				.name{
					display: block;
					font-size: 32rpx;
					color: #e3af2f;
				}
				.time{
					display: block;
					font-size: 28rpx;
					color: #999;
					padding: 15rpx 0;
				}
				.cmDtBox{
					font-size: 28rpx;
					line-height: 46rpx;
				}
				
			}
		}
	}
	.pltitle{
		font-size: 30rpx;
		font-weight: 600;
		padding: 20rpx;
	}
	.fbplbox{
		display: flex;
		padding: 20rpx;
		.myInput{
			flex: 1;
			height: 80rpx;
			background: #eee;
			padding: 0 15rpx;
			border-top-left-radius: 10rpx;
			border-bottom-left-radius: 10rpx;
			overflow: hidden;
		}
		.sbtn{
			display: flex;
			align-items: center;
			justify-content: center;
			height: 80rpx;
			background: #e6e6e6;
			width: 80rpx;
			border-top-right-radius: 10rpx;
			border-bottom-right-radius: 10rpx;
			overflow: hidden;
			.iconfont{
				font-size: 40rpx;
				color: #000;
			}
		}
	}
	.zjListBox{
		.zjListItem{
			display: flex;
			box-sizing: border-box;
			width: 100%;
			padding: 20rpx;
			margin: 0 0 20rpx 0;
			background: #fff;
			.tcInfo{
				flex: 1;
				flex-shrink: 0;
			}
			.lk{
				display: flex;
				align-items: center;
				flex-shrink: 0;
			}
			.zjjgprice{
				display: flex;
				align-items: center;
				justify-content: flex-end;
				flex: 1;
				flex-shrink: 0;
				color: #999;
				font-size: 24rpx;
				font-weight: normal;
				padding: 0 20rpx 0 0;
				.num{
					font-weight: bold;
					font-size: 36rpx;
					color: #ff1120;
					padding: 0 0 0 10rpx;
				}
			}
		}
	}
	
</style>
